/**
  ******************************************************************************
  * @file    rs485.c
  * @brief   This file provides code for the configuration
  *          of the RS485 instances.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2023 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/
#include "rs485.h"

/* Defines -------------------------------------------------------------------*/

/* Variables -----------------------------------------------------------------*/
char RS485DataBuff[1024] = {0};

/* Prototypes ----------------------------------------------------------------*/
void RS485_Init(void)
{

}

void RS485_SendData(uint32_t pin,UART_HandleTypeDef *huart,u8 *buf,u8 len)
{
    GpioWritePin(pin,1);
	HAL_UART_Transmit(huart,buf,len,1000);
    GpioWritePin(pin,0);
}

HAL_StatusTypeDef RS485_RecvData(uint32_t pin,UART_HandleTypeDef *huart,u8 *buf,u8 len)
{
    return HAL_UART_Receive(huart,(uint8_t*)buf,len,1000);
}

void DemoRS485Init(void)
{
    RS485_Init();
}
void DemoRS485(void)
{
    HAL_StatusTypeDef result;
    result = RS485_RecvData(RS485_DE_RE_PIN,&huart[RS485_UART_NO],(uint8_t*)RS485DataBuff,10);
    if(result == HAL_OK)
        RS485_SendData(RS485_DE_RE_PIN,&huart[RS485_UART_NO],(uint8_t*)RS485DataBuff,10);
}